package com.example.administrator.himalaya.live_button_activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.administrator.himalaya.R;
import com.example.administrator.himalaya.entity.live_button_entity.Live_Button_Entity;
import com.example.administrator.himalaya.live_button_adapter.Live_Button_Adapter;
import com.example.administrator.himalaya.service.Live_Button_Service;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class JingjiActivity extends AppCompatActivity implements View.OnClickListener, Callback<Live_Button_Entity> {

    private ImageView mBack;
    private Live_Button_Service mService;
    private ListView mListView;
    private List<Live_Button_Entity.DataEntity.Entity> datas = new ArrayList<>();
    private Live_Button_Adapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xinwen);
        TextView text_title = (TextView) findViewById(R.id.text_title);
        text_title.setText("经济台");
        mBack = (ImageView) findViewById(R.id.back);
        mBack.setOnClickListener(this);
        mListView = (ListView) findViewById(R.id.listView);
        mService = new Retrofit.Builder()
                .baseUrl("http://live.ximalaya.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(Live_Button_Service.class);
        mService.getList(11,1,20).enqueue(this);
        mAdapter = new Live_Button_Adapter(this, datas);
        mListView.setAdapter(mAdapter);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }

    @Override
    public void onResponse(Call<Live_Button_Entity> call, Response<Live_Button_Entity> response) {
        datas.addAll(response.body().getData().getData());
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFailure(Call<Live_Button_Entity> call, Throwable t) {

    }
}
